package com.moli.iov.admin.websocket.facotry;

import com.moli.iov.admin.websocket.service.WebSocketQueryService;
import com.moli.iov.admin.websocket.utils.WebSocketContant;
import com.moli.iov.util.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName WebSocketQueryServiceFactory
 * @Description service工厂类，获取spring用于websocket查询服务的service
 * @Author 李伟松
 * @CreateDate 2019-03-06 下午 5:49
 * @UpdateDate 2019-03-06 下午 5:49
 * @Version 1.0
 */
@Slf4j
public class WebSocketQueryServiceFactory {

    final static Map<String, String> beanNameAdapterMap = new HashMap<>();

    static {
//        beanNameAdapterMap.put(WebSocketContant.HOME_ALARM_FAILURE_LIST, "alarmWService");
        beanNameAdapterMap.put(WebSocketContant.ONLINE_MONITOR, "alarmStatisticsWService");
        beanNameAdapterMap.put(WebSocketContant.PARAMSETDETAIL_LIST, "paramSetDetailListWService");
        beanNameAdapterMap.put(WebSocketContant.QUERY_PARAM, "queryParamWService");
        beanNameAdapterMap.put(WebSocketContant.VEHICLE_MONITOR, "vehicleMonitorWService");
        beanNameAdapterMap.put(WebSocketContant.VEHICLE_TBOX, "vehicleTboxWService");
        beanNameAdapterMap.put(WebSocketContant.VEHICLEDETAIL_PAGE, "vehicleDetailPageWService");
        beanNameAdapterMap.put(WebSocketContant.VEHICLEMONITOR_DETAIL, "monitorDetailWService");
        beanNameAdapterMap.put(WebSocketContant.ALARM_COUNT_STATISTICS, "alarmStatisticsWService");
    }

    public static WebSocketQueryService getService(String beanName) {

        Map<String, WebSocketQueryService> result = SpringContextUtils.getApplicationContext().getBeansOfType(WebSocketQueryService.class);

        if (StringUtils.isEmpty(beanName)) {
            return null;
        }

        String adapterName = beanNameAdapterMap.get(beanName);
        beanName = StringUtils.isEmpty(adapterName) ? beanName : adapterName;
        return result.get(beanName);
    }

}
